package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.utils.UserContext;
import cn.wolfcode.trip.base.domain.TravelReplyComment;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.service.ITravelReplyCommentService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/travelComments")
public class TravelCommentController {

    @Autowired
    private ITravelService travelService;
    @Autowired
    private ITravelCommentService travelCommentService;
    @Autowired
    private ITravelReplyCommentService replyCommentService;


    @PostMapping("/replyComments")
    @ResponseBody
    public Object saveTravelComments(TravelReplyComment replyComment) {
        JSONResult result = new JSONResult();
        try {
            replyComment.setCreateTime(new Date());
            replyComment.setReplyUser(UserContext.getCurrentUser());
            replyCommentService.save(replyComment);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;

    }


}
